<html>
<body>
UID:403994037
<br/>
UID:503993985
<form action="query.php" method="post">

<textarea name="inputStr" rows="8" cols="60"></textarea>
<br/>

<input type="submit" value="Submit" />
<br/>

<?php

if(isset($_POST['inputStr']))
{
$qury= $_POST['inputStr'];
echo "<h3> Results from MySQL</h3>";


$con = mysql_connect("localhost","cs143","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("CS143", $con);


$result = mysql_query($qury);

if (!$result) {
    die(mysql_error());
}
echo "<table border=1>";
echo "<tr>";
$count=0;
$i = 0;
while ($i < mysql_num_fields($result)) {
    $meta = mysql_fetch_field($result, $i);
    echo "<th> ".$meta->name."</th>";
    $i++;
    $count++;
}
echo "</tr>";


$j=0;
while($row = mysql_fetch_array($result))
{	$j=0;
	echo "<tr>";
	while($j<$count)
    {	if($row[$j])
	    	echo "<td>".$row[$j]."</td>";
	    else
	    	echo "<td> N/A</td>";
	    $j++;
	}
	echo "</tr>";
}
 


/* get column metadata */


echo "</table>";
mysql_close($con);






}


?>
</body>
</html>